var p2p_touser = null;
var p2p_layerno = null;

var siteim_p2p_chat_ul = null;
var $siteim_p2p_chat_ul = null;

var siteim_p2p_chat_div = null;



$(function () {
	$siteim_p2p_chat_ul = $("#siteim_p2p_chat_ul");
	siteim_p2p_chat_ul = $siteim_p2p_chat_ul[0];
	siteim_p2p_chat_div = $("#siteim_p2p_chat_div")[0];
});

/**
 * 显示私聊框
 */
siteim.show_p2p_layer = function (simpleuser) {

	p2p_touser = simpleuser;
	var t = simpleuser.n;

	$siteim_p2p_chat_ul.html("");

	var req = {
		uid: p2p_touser.i
	};
	siteim.send(SiteImCommand.QUERY_P2P_CHAT_LOG_REQ, req);

	p2p_layerno = layer.open({
		title: t,
		type: 1,
		id: 897,
		offset: "auto",
		closeBtn: 0,
		// scrollbar : false,
		area: ["550px", "auto"], //'450px',//['450px', '450px'],
		isOutAnim: false, //禁用关闭动画，否则前面关闭再打开时会有问题
		content: $("#p2pchat_wrap"),
		btn: null,//["发 送", "重 选", "关 闭"],

		success: function(layero, index){
			chat_mode = 2;
		}
	});
};

siteim.close_p2p_layer = function() {
	chat_mode = 1;
	layer.close(p2p_layerno);
}

/**
 * 发送私聊
 */
siteim.p2p = function () {
	var text = getP2pContent();

	var req = {
		to: p2p_touser.i,
		c: text
	};
	siteim.send(SiteImCommand.P2P_CHAT_REQ, req);
	setP2pContent("");
};

function getP2pContent() {
	return $("#siteim_chat_text_2").val();
}

function setP2pContent(text) {
	return $("#siteim_chat_text_2").val(text);
}

/**
 * 私聊聊自动滚屏
 */
siteim.p2p_scroll_chat = function () {
	if (!siteim_lock_scroll_chat) {
		//不锁屏才自动滚屏
		siteim_p2p_chat_div.scrollTop = siteim_p2p_chat_div.scrollHeight;
	}
};

/**
 * 私聊天输入框架的回车事件
 */
siteim.p2p_chat_text_keyup = function (event) {
	if (/** event.ctrlKey && */ event.keyCode == 13) {
		siteim.p2p();
	}
};